package org.clevernote.main;

import java.util.List;

import org.clevernote.foundations.Authentication;
import org.clevernote.foundations.ClevernoteConstants;
import org.clevernote.foundations.StringConstants;
import org.clevernote.foundations.cmd.Cmd;

import com.evernote.edam.error.EDAMSystemException;
import com.evernote.edam.error.EDAMUserException;
import com.evernote.edam.notestore.NoteStore;
import com.evernote.edam.type.Notebook;
import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TBinaryProtocol;
import com.facebook.thrift.transport.THttpClient;

import ui.cmdline.parser.CommandLineArguments;
import ui.cmdline.parser.ParserException;

public class CmdListNotebooks implements Cmd {


	public static void main(String args[]) {

		try {
			CmdListNotebooks cmd = new CmdListNotebooks();

			CmdRunner.executeCmd(args, cmd);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	
	public void run(CommandLineArguments cmdline, Authentication auth)
			throws TException, EDAMSystemException, EDAMUserException {

		THttpClient noteStoreTrans = new THttpClient(auth.getNoteStoreUrl());
		TBinaryProtocol noteStoreProt = new TBinaryProtocol(noteStoreTrans);
		NoteStore.Client noteStore = new NoteStore.Client(noteStoreProt,
				noteStoreProt);

		// List all of the notes in the account
		List<Notebook> notebooks = (List<Notebook>) noteStore
				.listNotebooks(auth.getAuthenticationToken());

		for (Notebook notebook : notebooks) {
			System.out.println("Notebook: " + notebook.getName());
		}
	}

	
	public String getName() {
		return StringConstants.CMD_LIST_NOTEBOOKS;
	}
}
